enum UserScripts {
  DouYin = 'douyin',
}

export default defineBackground(() => {

  chrome.userScripts.configureWorld({
    messaging: true,
    csp: "script-src 'self'",
  })

  chrome.userScripts.register([
    {
      id: UserScripts.DouYin,
      world: 'MAIN',
      js: [{ file: 'user-scripts/douyin.js' }],
      matches: ['*://*.chrome.com/*', '*://*.douyin.com/*'],
      runAt: 'document_start',
    },
  ])

  chrome.runtime.onUserScriptMessage.addListener((message, sender, sendResponse) => {
    console.log({ message, sender, sendResponse })
    return undefined
  })

  chrome.runtime.onUserScriptConnect.addListener((port) => {
    console.log(port)
  })

  chrome.tabs.onUpdated.addListener((tabId, info) => {
    if (info.status === 'complete') {
      chrome.tabs.sendMessage(tabId, { data: '链接' })
    }
  })
})
